package top.jnaw.test.util.plugin;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class qqq {
  @SuppressWarnings("deprecation")
  public static void main(String[] args) {
    String fileToBeRead = "C:\\exp.xls"; // excel位置
    int coloum = 1; // 比如你要获取第1列
    try {
      HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(
          fileToBeRead));
      HSSFSheet sheet = workbook.getSheet("Sheet1");
      for (int i = 0; i <= sheet.getLastRowNum(); i++) {
        HSSFRow row = sheet.getRow((short) i);
        if (null == row) {
          continue;
        } else {
          HSSFCell cell = row.getCell((short) coloum);
          if (null == cell) {
            continue;
          } else {
            System.out.println(cell.getNumericCellValue());//原数据
            int temp = (int) cell.getNumericCellValue();//新数据
            cell.setCellValue(temp + 1);//修改数据
          }
        }
      }
      FileOutputStream out = null;
      try {
        out = new FileOutputStream(fileToBeRead);//写入存储文件
        workbook.write(out);
      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        try {
          out.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}